//
//  Community.m
//  Four_Fit
//
//  Created by lanou on 16/7/13.
//  Copyright © 2016年 xmaz. All rights reserved.
//

#import "Community.h"
#import "comment.h"

@implementation Community

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
    if ([key isEqualToString:@"id"]) {
        [self setValue:value forKey:@"ID"];
    }
    
}

- (CGFloat)cellHeight {
    
    if (!_cellHeight) {

        
            if (_items.count > 0) {
                
                _commentViewH = 80;
           
            } else {
                _commentViewH = 0;
            }
        
        // 文字的最大尺寸
        CGSize maxSize = CGSizeMake([UIScreen mainScreen].bounds.size.width - 30, MAXFLOAT);
        //计算标题文字所需要的高度
        CGFloat titleTextH = [_title boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:22]} context:nil].size.height;
        
        //计算内容文字所需要的高度
        CGFloat contentTextH = [_content boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14]} context:nil].size.height;
        
        if (_title.length == 0) {
            
            titleTextH = 15;
        }
        
        if (contentTextH > 60) {
            
            if (_pic.count == 1) {
                
                _pictureViewFrame = CGRectMake(20, 70 + titleTextH + 60 + 20, kWidth - 40, kWidth - 30);
                
                _cellHeight = 70 + titleTextH + 60 + 20 + kWidth - 20 + _commentViewH + 10;
                
            } else if (_pic.count == 2) {
                
                _pictureViewFrame = CGRectMake(20, 70 + titleTextH + 60 + 20, kWidth - 40, 180);
                
                _cellHeight = 70 + titleTextH + 60  + 20+ 180 + _commentViewH + 20;
                
            } else if (_pic.count == 3) {
                
                _pictureViewFrame = CGRectMake(20, 70 + titleTextH + 60 + 20, kWidth - 40, kWidth - 100);
                
                _cellHeight = 70 + titleTextH + 60 + 20 + kWidth - 100 + _commentViewH + 20;
            } else if (_pic.count == 0) {
                
                _cellHeight = 70 + titleTextH + 60 + 20 + _commentViewH + 20;
            }
            
            
            
    } else {
        
        
        if (_pic.count == 1) {
            
            _pictureViewFrame = CGRectMake(20, 70 + titleTextH + contentTextH + 20, kWidth - 40, kWidth - 30);
            
            _cellHeight = 70 + titleTextH + 20 + contentTextH + kWidth - 20 + _commentViewH + 10;
        } else if (_pic.count == 2) {
            
            _pictureViewFrame = CGRectMake(20, 70 + titleTextH + contentTextH + 20, kWidth - 40, 180);
            
            _cellHeight = 70 + titleTextH + contentTextH + 20 + 180 + _commentViewH + 20;
            
        } else if (_pic.count == 3) {
            
            _pictureViewFrame = CGRectMake(20, 70 + titleTextH + 20 + contentTextH, kWidth - 40, kWidth - 100);
            
            _cellHeight = 70 + titleTextH + contentTextH + 20 + kWidth - 100 + _commentViewH + 20;
        } else if (_pic.count == 0) {
            
            _cellHeight = 70 + titleTextH + contentTextH + 20 + _commentViewH + 20;
        }
        
        
    }
    


}


    return _cellHeight;
}


@end
